package com.bj58.ecdata.dashboard.controllers;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.bj58.ecdata.dashboard.constant.CalendarConst;
import com.bj58.ecdata.dashboard.constant.EnumCate;
import com.bj58.ecdata.dashboard.constant.ResumeConst;
import com.bj58.ecdata.dashboard.databll.PriviledgeBLL;
import com.bj58.ecdata.dashboard.utils.MyServletRequestUtils;
import com.bj58.groupbuy.action.model.User;
import com.bj58.groupbuy.action.util.SomePublicUtil;
import com.bj58.wf.mvc.ActionResult;
import com.bj58.wf.mvc.MvcController;
import com.bj58.wf.mvc.annotation.GET;
import com.bj58.wf.mvc.annotation.POST;
import com.bj58.wf.mvc.annotation.Path;

/**
 * 万年历看板Controller
 * 
 * @author guoxue 2015-11-16
 */
@Path("/calendar")
public class CalendarController extends MvcController {
	private SomePublicUtil spu = new SomePublicUtil();
	
//	private final AbstractBaseService<CalendarSource> calendarSourceService = ServiceBeanFactory.get(CalendarSource.class, null);

	/**
	 * 万年历——节日城市数据
	 *  三端  总体
	 * @param
	 * @return
	 * @author guoxue 2015-11-16
	 */
	@Path({ "/festival_city" })
	// @Check("dashboard/calendar/festival_city")
	@GET
	@POST
	public ActionResult calendar_festival() {
		EnumCate cateEnum = null;
		try{
				
			HttpServletRequest request = beat.getRequest();
			User user = spu.getUserByCookie(request);
			//检查业务线权限
			String[] businessOpers = PriviledgeBLL.businessOperCheck(user).split(",");
			
			String businessName = MyServletRequestUtils.getStringParameter(request, "businessName",businessOpers[0]);
			cateEnum = EnumCate.valueOf(businessName);
			
			Map<String, Object> context = beat.getModel().getModel();
		
			context.put("businessName", businessName);
			context.put("businessList",businessOpers);  //权限有的业务线列表
			context.put("business_CN_Map",EnumCate.business_CN_Map);   //对应中文名
			
			//城市和类别
			context.put("CityList",ResumeConst.CityList);
			context.put("CateList",CalendarConst.getCateListByBusiness(businessName));	
			context.put("FestivalList",CalendarConst.FestivalList);
			
			if(!EnumCate.total.equals(cateEnum)){
				context.put("businessName_CN", cateEnum.getDBName()); //业务线标签名
			}		
			
		} catch (Exception e) {
			return ActionResult.view("null");
		}
		return ActionResult.view("calendar/festival_city");
	}
	
	/**
	 * 万年历——节日来源数据
	 *  pc m
	 * @param
	 * @return
	 * @author guoxue 2015-11-23
	 */
	@Path({ "/festival_source" })
	// @Check("dashboard/calendar/festival_source")
	@GET
	@POST
	public ActionResult calendar_source() {
		EnumCate cateEnum = null;
		try{
				
			HttpServletRequest request = beat.getRequest();
			User user = spu.getUserByCookie(request);
			//检查业务线权限
			String[] businessOpers = PriviledgeBLL.businessOperCheck(user).split(",");
			
			String businessName = MyServletRequestUtils.getStringParameter(request, "businessName",businessOpers[0]);
			cateEnum = EnumCate.valueOf(businessName);
			
			Map<String, Object> context = beat.getModel().getModel();
		
			context.put("businessName", businessName);
			context.put("businessList",businessOpers);  //权限有的业务线列表
			context.put("business_CN_Map",EnumCate.business_CN_Map);   //对应中文名
			
			//类别
			context.put("CateList",CalendarConst.getCateListByBusiness(businessName));			
			context.put("FestivalList",CalendarConst.FestivalList);
			
			if(!EnumCate.total.equals(cateEnum)){
				context.put("businessName_CN", cateEnum.getDBName()); //业务线标签名
			}		
			
		} catch (Exception e) {
			return ActionResult.view("null");
		}
		return ActionResult.view("calendar/festival_source");
	}
	
	
	/**
	 * 万年历——淡旺季城市数据
	 *  三端  总体
	 * @param
	 * @return
	 * @author guoxue 2015-11-30
	 */
	@Path({ "/season_city" })
	// @Check("dashboard/calendar/season_city")
	@GET
	@POST
	public ActionResult season_city() {
		EnumCate cateEnum = null;
		try{
				
			HttpServletRequest request = beat.getRequest();
			User user = spu.getUserByCookie(request);
			//检查业务线权限
			String[] businessOpers = PriviledgeBLL.businessOperCheck(user).split(",");
			
			String businessName = MyServletRequestUtils.getStringParameter(request, "businessName",businessOpers[0]);
			cateEnum = EnumCate.valueOf(businessName);
			
			Map<String, Object> context = beat.getModel().getModel();
		
			context.put("businessName", businessName);
			context.put("businessList",businessOpers);  //权限有的业务线列表
			context.put("business_CN_Map",EnumCate.business_CN_Map);   //对应中文名
			
			//城市和类别
			context.put("CityList",ResumeConst.CityList);
			context.put("CateList",CalendarConst.getCateListByBusiness(businessName));
			
			if(!EnumCate.total.equals(cateEnum)){
				context.put("businessName_CN", cateEnum.getDBName()); //业务线标签名
			}		
			
		} catch (Exception e) {
			return ActionResult.view("null");
		}
		return ActionResult.view("calendar/season_city");
	}
	
	/**
	 * 万年历——淡旺季来源数据
	 *  总体  pc m
	 * @param
	 * @return
	 * @author guoxue 2015-11-30
	 */
	@Path({ "/season_source" })
	// @Check("dashboard/calendar/season_source")
	@GET
	@POST
	public ActionResult season_source() {
		EnumCate cateEnum = null;
		try{
				
			HttpServletRequest request = beat.getRequest();
			User user = spu.getUserByCookie(request);
			//检查业务线权限
			String[] businessOpers = PriviledgeBLL.businessOperCheck(user).split(",");
			
			String businessName = MyServletRequestUtils.getStringParameter(request, "businessName",businessOpers[0]);
			cateEnum = EnumCate.valueOf(businessName);
			
			Map<String, Object> context = beat.getModel().getModel();
		
			context.put("businessName", businessName);
			context.put("businessList",businessOpers);  //权限有的业务线列表
			context.put("business_CN_Map",EnumCate.business_CN_Map);   //对应中文名
			
			//类别
			context.put("CateList",CalendarConst.getCateListByBusiness(businessName));
			
			if(!EnumCate.total.equals(cateEnum)){
				context.put("businessName_CN", cateEnum.getDBName()); //业务线标签名
			}
			
			String maxDate_pc="2015-12-01";
			//String maxDate = calendarSourceService.getMaxDate();	  这个也要分表哦	
			context.put("maxDate_pc", maxDate_pc);
			
			String maxDate_m="2015-12-01";
			context.put("maxDate_m", maxDate_m);
			
		} catch (Exception e) {
			return ActionResult.view("null");
		}
		return ActionResult.view("calendar/season_source");
	}
	
}
